package cn.kgc.ubagnet.controller;

import cn.kgc.ubagnet.pojo.Buyer;
import cn.kgc.ubagnet.service.buyer.BuyerService;
import cn.kgc.ubagnet.utils.ResultEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author shkstart
 * @create 2020-08-04 11:37
 */
@RestController
@Controller
public class BuyerController {

    @Resource
    BuyerService buyerService;


    @RequestMapping("/login")
    public ResultEntity<Map<String,Object>> login(
            @RequestParam("phone")String phone,
            @RequestParam("password") String password,
            Model model){

        Buyer login = buyerService.login(phone, password);
        Map<String,Object> map=new HashMap<>();
        map.put("phone",phone);
        if(login!=null){
            map.put("msg","SUCCESS");
        }else{
            map.put("msg","FAILED");
        }
    return ResultEntity.successWithoutData(map);

    }

    @RequestMapping("/regist/buyer")
    public ResultEntity<Integer> registBuyer(@RequestBody Buyer buyer){
        Integer integer = buyerService.addBuyer(buyer);
        return ResultEntity.successWithoutData(integer);
    }


   /* @RequestMapping("/login")
    public String doLogin(
            @RequestParam("phone")String phone,
            @RequestParam("password") String password,
            Model model,
            HttpSession session) {
        Buyer login = buyerService.login(phone, password);
        if (login == null) {
            model.addAttribute("login", phone);
            model.addAttribute("error", "账号或密码错误");
            return "index";
        }
        session.setAttribute("login", login);
        return "redirect:static/index01.html";
    }*/

}
